        $(function () {  
            $("#tt").tree(
                    {
                        url : basePath+"itemCat/loadTree",
                    	loadFilter: function(rows){
                    		return convert(rows);
                    	},
                        onClick: function (node) {  
                        	$("#catalog",window.parent.document).attr("value",node.id);//子窗口给父窗口元素赋值
                        }
                    }); 
  
        });  

  
        function convert(rows){
        	function exists(rows, parentId){
        		for(var i=0; i<rows.length; i++){
        			if (rows[i].id == parentId) return true;
        		}
        		return false;
        	}
        	
        	var nodes = [];
        	// get the top level nodes
        	for(var i=0; i<rows.length; i++){
        		var row = rows[i];
        		if (!exists(rows, row.parentId)){
        			nodes.push({
        				id:row.id,
        				text:row.name
        			});
        		}
        	}
        	
        	var toDo = [];
        	for(var i=0; i<nodes.length; i++){
        		toDo.push(nodes[i]);
        	}
        	while(toDo.length){
        		var node = toDo.shift();	// the parent node
        		// get the children nodes
        		for(var i=0; i<rows.length; i++){
        			var row = rows[i];
        			if (row.parentId == node.id){
        				var child = {id:row.id,text:row.name};
        				if (node.children){
        					node.children.push(child);
        				} else {
        					node.children = [child];
        				}
        				toDo.push(child);
        			}
        		}
        	}
        	return nodes;
        } 
  
